package com.android.equipment.adapter

import android.annotation.SuppressLint
import android.view.View
import android.widget.TextView
import com.android.equipment.R
import com.android.equipment.config.Constant
import com.android.equipment.dao.DeviceModel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class DeviceModelManagerAdapter(layoutResId: Int) :
    BaseQuickAdapter<DeviceModel, BaseViewHolder>(layoutResId) {
    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: DeviceModel) {
        holder.setText(R.id.tv_model_name, item.deviceModel)
        holder.setText(R.id.tv_model_code, item.modelCode)
        holder.setText(R.id.tv_prefix, item.prefix)
        holder.setText(R.id.tv_protocol, Constant.protocolList[item.protocol])
        holder.setText(R.id.tv_create_time, item.createTime)
        val tvUpdateTime = holder.getView<TextView>(R.id.tv_update_time)
        if (item.updateTime.isNullOrEmpty()) {
            tvUpdateTime.visibility = View.GONE
        } else {
            tvUpdateTime.visibility = View.VISIBLE
            tvUpdateTime.text = item.updateTime
        }
    }
}